home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / WaveText / WaveText.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  10.0 KB  |  489 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. import java.net.URLEncoder;
  16.  
  17. public class WaveText extends Applet implements Runnable, MouseListener {
  18.    private Thread thread;
  19.    // $FF: renamed from: b java.awt.Graphics
  20.    private Graphics field_0;
  21.    private Image buffer;
  22.    private Image backImage;
  23.    private boolean loaded = false;
  24.    private boolean isBackImage = false;
  25.    private boolean paintable = false;
  26.    private boolean move = true;
  27.    private boolean firstime = true;
  28.    private int amplitude;
  29.    // $FF: renamed from: wi int
  30.    private int field_1;
  31.    // $FF: renamed from: he int
  32.    private int field_2;
  33.    private int decy;
  34.    private int decx;
  35.    private int pause;
  36.    private int text_height;
  37.    private int text_width;
  38.    private int pas;
  39.    // $FF: renamed from: X int
  40.    private int field_3;
  41.    private int long_string;
  42.    private float angle_step;
  43.    private float phir_step;
  44.    private float phi;
  45.    private float phir;
  46.    private Color textColor;
  47.    private String backImageName;
  48.    private String text;
  49.    private Color backColor;
  50.    // $FF: renamed from: fm java.awt.FontMetrics
  51.    private FontMetrics field_4;
  52.    private int wiBack;
  53.    private int heBack;
  54.    private Color enterBackColor;
  55.    private Color enterTextColor;
  56.    private AudioClip sound;
  57.    private AudioClip clicSound;
  58.    private AudioClip enterSound;
  59.    private boolean loopSound;
  60.    private String link;
  61.    private String statusBarText;
  62.  
  63.    public String getAppletInfo() {
  64.       return "Name: WaveText\r\nAuthor: Taiji Software\r\n";
  65.    }
  66.  
  67.    public WaveText() {
  68.       this.move = true;
  69.       this.amplitude = 40;
  70.       this.pause = 5;
  71.       this.text_height = 10;
  72.       this.pas = 3;
  73.       this.angle_step = 95.0F;
  74.       ((Component)this).addMouseListener(this);
  75.    }
  76.  
  77.    public void register() {
  78.       try {
  79.          URL u = new URL("http://www.taijisoftware.com");
  80.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  81.          this.stop();
  82.       } catch (Exception e) {
  83.          System.out.println(e);
  84.          this.stop();
  85.       }
  86.    }
  87.  
  88.    public void init() {
  89.       String codeBase = null;
  90.  
  91.       try {
  92.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  93.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  94.          codeBase = codeBase.toUpperCase();
  95.       } catch (Exception var9) {
  96.       }
  97.  
  98.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  99.          String regCode = ((Applet)this).getParameter("registration_code");
  100.          if (regCode == null) {
  101.             regCode = ((Applet)this).getParameter("reg_domain");
  102.             if (regCode == null) {
  103.                this.register();
  104.             } else {
  105.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  106.                   codeBase = "WWW." + codeBase;
  107.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  108.                   codeBase = codeBase.substring(4);
  109.                }
  110.  
  111.                char[] chars = new char[codeBase.length()];
  112.                codeBase.getChars(0, codeBase.length(), chars, 0);
  113.                String key = new String("haricot");
  114.                char[] chars2 = new char[key.length()];
  115.                key.getChars(0, key.length(), chars2, 0);
  116.  
  117.                for(int i = 0; i < codeBase.length(); ++i) {
  118.                   int j;
  119.                   if (i >= key.length()) {
  120.                      j = i - key.length() * (i / key.length());
  121.                   } else {
  122.                      j = i;
  123.                   }
  124.  
  125.                   chars[i] += chars2[j];
  126.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  127.                }
  128.  
  129.                String res = new String(chars);
  130.                if (!res.equalsIgnoreCase(regCode)) {
  131.                   this.register();
  132.                }
  133.             }
  134.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  135.             this.register();
  136.          }
  137.       }
  138.  
  139.       this.getParameters();
  140.       this.field_3 = this.field_1;
  141.       if (this.sound != null) {
  142.          if (this.loopSound) {
  143.             this.sound.loop();
  144.             return;
  145.          }
  146.  
  147.          this.sound.play();
  148.       }
  149.  
  150.    }
  151.  
  152.    public void getParameters() {
  153.       String s = ((Applet)this).getParameter("pause");
  154.       if (s != null) {
  155.          this.pause = Integer.parseInt(s);
  156.       }
  157.  
  158.       this.field_1 = ((Component)this).getSize().width;
  159.       this.field_2 = ((Component)this).getSize().height;
  160.       this.text = ((Applet)this).getParameter("text");
  161.       if (this.text == null) {
  162.          this.text = "no text !!";
  163.       }
  164.  
  165.       this.textColor = this.getColor("text_color");
  166.       this.backColor = this.getColor("background_color");
  167.       ((Component)this).setBackground(this.backColor);
  168.       this.backImageName = ((Applet)this).getParameter("background_image");
  169.       if (this.backImageName != null) {
  170.          this.isBackImage = true;
  171.       }
  172.  
  173.       s = ((Applet)this).getParameter("text_height");
  174.       if (s != null) {
  175.          this.text_height = Integer.parseInt(s);
  176.       }
  177.  
  178.       s = ((Applet)this).getParameter("height_shift");
  179.       if (s != null) {
  180.          this.decy = Integer.parseInt(s);
  181.       }
  182.  
  183.       s = ((Applet)this).getParameter("step");
  184.       if (s != null) {
  185.          this.pas = Integer.parseInt(s);
  186.       }
  187.  
  188.       s = ((Applet)this).getParameter("angle_step");
  189.       if (s != null) {
  190.          this.angle_step = (float)Integer.parseInt(s);
  191.       }
  192.  
  193.       s = ((Applet)this).getParameter("amplitude");
  194.       if (s != null) {
  195.          this.amplitude = Integer.parseInt(s);
  196.       }
  197.  
  198.       s = ((Applet)this).getParameter("phir_step");
  199.       if (s != null) {
  200.          this.phir_step = (float)Integer.parseInt(s);
  201.       } else {
  202.          this.phir_step = (float)((int)((float)this.pas * this.angle_step * (float)this.text.length() / (float)this.long_string));
  203.       }
  204.  
  205.       this.text_width = 3 * this.text_height / 4;
  206.       this.enterBackColor = this.getColor("enter_background_color");
  207.       this.enterTextColor = this.getColor("enter_text_color");
  208.       s = ((Applet)this).getParameter("text_height");
  209.       if (s != null) {
  210.          this.text_height = Integer.parseInt(s);
  211.       }
  212.  
  213.       s = ((Applet)this).getParameter("height_shift");
  214.       if (s != null) {
  215.          this.decy = Integer.parseInt(s);
  216.       }
  217.  
  218.       s = ((Applet)this).getParameter("width_shift");
  219.       if (s != null) {
  220.          this.decx = Integer.parseInt(s);
  221.       }
  222.  
  223.       this.backImageName = ((Applet)this).getParameter("background_image");
  224.       if (this.backImageName != null) {
  225.          this.isBackImage = true;
  226.       }
  227.  
  228.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  229.       s = ((Applet)this).getParameter("sound_name");
  230.       if (s != null) {
  231.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  232.       }
  233.  
  234.       s = ((Applet)this).getParameter("loop_sound");
  235.       if (s != null) {
  236.          if (s.equals("yes")) {
  237.             this.loopSound = true;
  238.          } else {
  239.             this.loopSound = false;
  240.          }
  241.       }
  242.  
  243.       s = ((Applet)this).getParameter("clic_sound_name");
  244.       if (s != null) {
  245.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  246.       }
  247.  
  248.       s = ((Applet)this).getParameter("enter_sound_name");
  249.       if (s != null) {
  250.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  251.       }
  252.  
  253.       this.link = ((Applet)this).getParameter("link");
  254.    }
  255.  
  256.    public Color getColor(String param) {
  257.       String s = ((Applet)this).getParameter(param);
  258.       if (s != null) {
  259.          if (s.substring(0, 1).equals("#")) {
  260.             s = s.substring(1);
  261.             int i = Integer.parseInt(s, 16);
  262.             return new Color(i);
  263.          } else {
  264.             return null;
  265.          }
  266.       } else {
  267.          return null;
  268.       }
  269.    }
  270.  
  271.    public final void paint(Graphics g) {
  272.       if (this.paintable) {
  273.          this.field_0.clearRect(0, 0, this.field_1, this.field_2);
  274.          if (this.isBackImage & this.loaded) {
  275.             this.field_0.drawImage(this.backImage, (this.field_1 - this.wiBack) / 2, (this.field_2 - this.heBack) / 2, this);
  276.          }
  277.  
  278.          int index = 0;
  279.          this.phi = this.phir;
  280.  
  281.          for(int i = 0; i < this.text.length(); ++i) {
  282.             String s = this.text.substring(i, i + 1);
  283.             this.field_0.drawString(s, this.field_3 + index, (int)((double)this.amplitude * Math.sin((double)this.phi * Math.PI / (double)180.0F)) + this.text_height + this.decy);
  284.             index += this.field_4.stringWidth(s);
  285.             this.phi += this.angle_step;
  286.          }
  287.  
  288.          this.phir += this.phir_step;
  289.          g.drawImage(this.buffer, 0, 0, this);
  290.       }
  291.  
  292.    }
  293.  
  294.    public final void update(Graphics g) {
  295.       this.paint(g);
  296.    }
  297.  
  298.    public void start() {
  299.       this.move = true;
  300.       if (this.thread == null) {
  301.          this.thread = new Thread(this);
  302.          this.thread.start();
  303.       }
  304.  
  305.    }
  306.  
  307.    public void stop() {
  308.       if (this.thread != null) {
  309.          this.move = false;
  310.          this.thread = null;
  311.       }
  312.  
  313.       if (this.sound != null) {
  314.          this.sound.stop();
  315.       }
  316.  
  317.    }
  318.  
  319.    public void run() {
  320.       if (this.firstime) {
  321.          if (this.isBackImage) {
  322.             MediaTracker tracker = new MediaTracker(this);
  323.             this.backImage = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.backImageName);
  324.             tracker.addImage(this.backImage, 0);
  325.  
  326.             try {
  327.                tracker.waitForAll();
  328.                this.loaded = !tracker.isErrorAny();
  329.             } catch (InterruptedException var5) {
  330.                this.stop();
  331.             }
  332.  
  333.             if (!this.loaded) {
  334.                this.stop();
  335.                return;
  336.             }
  337.          }
  338.  
  339.          this.buffer = ((Component)this).createImage(this.field_1, this.field_2);
  340.          this.field_0 = this.buffer.getGraphics();
  341.          if (this.isBackImage) {
  342.             this.wiBack = this.backImage.getWidth(this);
  343.             this.heBack = this.backImage.getHeight(this);
  344.          }
  345.  
  346.          String fontName = ((Applet)this).getParameter("text_font");
  347.          if (fontName == null) {
  348.             fontName = "TimesRoman";
  349.          }
  350.  
  351.          int style = 1;
  352.          String s = ((Applet)this).getParameter("text_style");
  353.          if (s != null) {
  354.             if (s.equals("bold")) {
  355.                style = 1;
  356.             } else if (s.equals("italic")) {
  357.                style = 2;
  358.             } else if (s.equals("bold_italic")) {
  359.                style = 3;
  360.             } else {
  361.                style = 0;
  362.             }
  363.          }
  364.  
  365.          this.field_0.setFont(new Font(fontName, style, this.text_height));
  366.          this.field_4 = this.field_0.getFontMetrics();
  367.          if (this.decy == 0) {
  368.             this.decy = (this.field_2 + this.field_4.getMaxAscent() - this.field_4.getMaxDescent()) / 2 - this.text_height;
  369.          }
  370.  
  371.          this.long_string = this.field_4.stringWidth(this.text);
  372.          this.field_0.setColor(this.textColor);
  373.          this.paintable = true;
  374.          this.firstime = false;
  375.       }
  376.  
  377.       while(this.move) {
  378.          ((Component)this).repaint();
  379.          this.field_3 -= this.pas;
  380.          if (this.field_3 < -this.long_string) {
  381.             this.field_3 = this.field_1;
  382.             this.phir = 0.0F;
  383.          }
  384.  
  385.          try {
  386.             Thread.sleep((long)this.pause);
  387.          } catch (InterruptedException e) {
  388.             System.err.println(e);
  389.             this.stop();
  390.          }
  391.       }
  392.  
  393.    }
  394.  
  395.    public URL giveURL(String url) {
  396.       try {
  397.          if (url.toUpperCase().startsWith("HTTP")) {
  398.             return new URL(url);
  399.          } else if (url.toUpperCase().startsWith("FTP")) {
  400.             int p = url.indexOf(":");
  401.             int p2 = url.indexOf(":", p + 1);
  402.             if (p2 != -1) {
  403.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  404.             }
  405.  
  406.             p = url.indexOf("%40");
  407.             if (p != -1) {
  408.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  409.             }
  410.  
  411.             return new URL(url);
  412.          } else {
  413.             return new URL(((Applet)this).getCodeBase(), url);
  414.          }
  415.       } catch (MalformedURLException e) {
  416.          System.out.println(e);
  417.          return null;
  418.       }
  419.    }
  420.  
  421.    public void mouseClicked(MouseEvent e) {
  422.    }
  423.  
  424.    public void mouseEntered(MouseEvent e) {
  425.       if (this.enterBackColor != null) {
  426.          ((Component)this).setBackground(this.enterBackColor);
  427.          ((Component)this).repaint();
  428.       }
  429.  
  430.       if (this.enterTextColor != null) {
  431.          if (this.field_0 != null) {
  432.             this.field_0.setColor(this.enterTextColor);
  433.          }
  434.  
  435.          ((Component)this).repaint();
  436.       }
  437.  
  438.       if (this.statusBarText != null) {
  439.          ((Applet)this).showStatus(this.statusBarText);
  440.       }
  441.  
  442.       if (this.enterSound != null) {
  443.          this.enterSound.play();
  444.       }
  445.  
  446.       if (this.link != null) {
  447.          ((Component)this).setCursor(new Cursor(12));
  448.       }
  449.  
  450.    }
  451.  
  452.    public void mouseExited(MouseEvent e) {
  453.       if (this.enterBackColor != null) {
  454.          ((Component)this).setBackground(this.backColor);
  455.          ((Component)this).repaint();
  456.       }
  457.  
  458.       if (this.enterTextColor != null) {
  459.          this.field_0.setColor(this.textColor);
  460.          ((Component)this).repaint();
  461.       }
  462.  
  463.       if (this.link != null) {
  464.          ((Component)this).setCursor(new Cursor(0));
  465.       }
  466.  
  467.    }
  468.  
  469.    public void mousePressed(MouseEvent e) {
  470.       if (this.clicSound != null) {
  471.          this.clicSound.play();
  472.       }
  473.  
  474.       if (this.link != null) {
  475.          String target = ((Applet)this).getParameter("target");
  476.          if (target == null) {
  477.             target = "_blank";
  478.          }
  479.  
  480.          URL u = this.giveURL(this.link);
  481.          ((Applet)this).getAppletContext().showDocument(u, target);
  482.       }
  483.  
  484.    }
  485.  
  486.    public void mouseReleased(MouseEvent e) {
  487.    }
  488. }
  489.